import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterdemo/0demo/utils/bus.dart';

import 'login_page.dart';
import 'page3.dart';

class Page2 extends StatefulWidget {
  @override
  _Page2State createState() => _Page2State();
}

class _Page2State extends State<Page2> {

  @override
  void initState() {
    Bus.instance.on("main2login", (arg) {
      Navigator.pushAndRemoveUntil(context, CupertinoPageRoute(builder: (context) => LoginPage()), (route) => false);
      // Navigator.pushReplacement(context, CupertinoPageRoute(builder: (context) => LoginPage()));
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("main page"),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: () {
            Navigator.push(context, CupertinoPageRoute(builder: (context) => Page3()));
          },
          child: Text("go2page3"),
        ),
      ),
    );
  }
}
